using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using EcsSiteDSTableAdapters;

namespace SiteECSWeb
{
    [DataObject]
    public class HeadAuthorsBLL
    {
        private HeadAuthorsTableAdapter _HeadAuthorsAdapter = null;

        protected HeadAuthorsTableAdapter HeadAuthorsAdapter
        {
            get
            {
                if (_HeadAuthorsAdapter == null)
                {
                    _HeadAuthorsAdapter = new HeadAuthorsTableAdapter();
                }
                return _HeadAuthorsAdapter;
            }
        }
        #region SelectAuthorities
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public EcsSiteDS.HeadAuthorsDataTable GetHeadAuthors()
        {
            return HeadAuthorsAdapter.GetHeadAuthorsRowRankData();
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.HeadAuthorsDataTable GetHeadAuthorsByAuthID(int HdAuthor_ID)
        {
            return HeadAuthorsAdapter.GetHeadAuthorsDataByHdAuthorID(HdAuthor_ID);
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public EcsSiteDS.HeadAuthorsDataTable GetHeadAuthorsByRowRank(int RowRank)
        {
            return HeadAuthorsAdapter.GetHeadAuthorsDataByRowRank(RowRank);
        }

        #endregion

        #region InsertAuthorities
        [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
        public int AddHeadAuthors(string HdAuthor_PreTitlear, string HdAuthor_Namear, string HdAuthor_Titlear1, 
            string HdAuthor_Titlear2, string HdAuthor_PreTitleen, string HdAuthor_Nameen, 
            string HdAuthor_Titleen1, string HdAuthor_Titleen2, string HdAuthor_Phone, 
            string HdAuthor_Fax, string HdAuthor_Email, int Auth_ID)
        {
            
            EcsSiteDS.HeadAuthorsDataTable HeadAuthorsTable = new EcsSiteDS.HeadAuthorsDataTable();
            EcsSiteDS.HeadAuthorsRow HeadAuthorsRow = HeadAuthorsTable.NewHeadAuthorsRow();

            if (string.IsNullOrEmpty(HdAuthor_Titlear2)) HeadAuthorsRow.SetHdAuthor_Titlear2Null(); else HeadAuthorsRow.HdAuthor_Titlear2 = HdAuthor_Titlear2;
            if (string.IsNullOrEmpty(HdAuthor_PreTitleen)) HeadAuthorsRow.SetHdAuthor_PreTitleenNull(); else HeadAuthorsRow.HdAuthor_PreTitleen = HdAuthor_PreTitleen;
            if (string.IsNullOrEmpty(HdAuthor_Nameen)) HeadAuthorsRow.SetHdAuthor_NameenNull(); else HeadAuthorsRow.HdAuthor_Nameen = HdAuthor_Nameen;
            if (string.IsNullOrEmpty(HdAuthor_Titleen1)) HeadAuthorsRow.SetHdAuthor_Titleen1Null(); else HeadAuthorsRow.HdAuthor_Titleen1 = HdAuthor_Titleen1;
            if (string.IsNullOrEmpty(HdAuthor_Titleen2)) HeadAuthorsRow.SetHdAuthor_Titleen2Null(); else HeadAuthorsRow.HdAuthor_Titleen2 = HdAuthor_Titleen2;
            if (string.IsNullOrEmpty(HdAuthor_Phone)) HeadAuthorsRow.SetHdAuthor_PhoneNull(); else HeadAuthorsRow.HdAuthor_Phone = HdAuthor_Phone;
            if (string.IsNullOrEmpty(HdAuthor_Fax)) HeadAuthorsRow.SetHdAuthor_FaxNull(); else HeadAuthorsRow.HdAuthor_Fax = HdAuthor_Fax;
            if (string.IsNullOrEmpty(HdAuthor_Email)) HeadAuthorsRow.SetHdAuthor_EmailNull(); else HeadAuthorsRow.HdAuthor_Email = HdAuthor_Email;


            HeadAuthorsRow.HdAuthor_PreTitlear = HdAuthor_PreTitlear;
            HeadAuthorsRow.HdAuthor_Namear = HdAuthor_Namear;
            HeadAuthorsRow.HdAuthor_Titlear1 = HdAuthor_Titlear1;
            HeadAuthorsRow.Auth_ID = Auth_ID;

            HeadAuthorsTable.AddHeadAuthorsRow(HeadAuthorsRow);

            int rowsAffected = HeadAuthorsAdapter.Update(HeadAuthorsTable);

            return (rowsAffected == 1) ? HeadAuthorsRow.HdAuthor_ID : -1;
        }


          #endregion

        #region UpdateAuthorities
        [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
        public bool UpdateAuthorty(string HdAuthor_PreTitlear, string HdAuthor_Namear, string HdAuthor_Titlear1,
            string HdAuthor_Titlear2, string HdAuthor_PreTitleen, string HdAuthor_Nameen,
            string HdAuthor_Titleen1, string HdAuthor_Titleen2, string HdAuthor_Phone,
            string HdAuthor_Fax, string HdAuthor_Email, int Auth_ID, int HdAuthor_ID)
        {
            EcsSiteDS.HeadAuthorsDataTable HeadAuthorsTable =
                HeadAuthorsAdapter.GetHeadAuthorsDataByHdAuthorID(HdAuthor_ID);
            if (HeadAuthorsTable.Count == 0)
            {
                return false;
            }

            EcsSiteDS.HeadAuthorsRow HeadAuthorsRow = HeadAuthorsTable[0];

            if (string.IsNullOrEmpty(HdAuthor_Titlear2)) HeadAuthorsRow.SetHdAuthor_Titlear2Null(); else HeadAuthorsRow.HdAuthor_Titlear2 = HdAuthor_Titlear2;
            if (string.IsNullOrEmpty(HdAuthor_PreTitleen)) HeadAuthorsRow.SetHdAuthor_PreTitleenNull(); else HeadAuthorsRow.HdAuthor_PreTitleen = HdAuthor_PreTitleen;
            if (string.IsNullOrEmpty(HdAuthor_Nameen)) HeadAuthorsRow.SetHdAuthor_NameenNull(); else HeadAuthorsRow.HdAuthor_Nameen = HdAuthor_Nameen;
            if (string.IsNullOrEmpty(HdAuthor_Titleen1)) HeadAuthorsRow.SetHdAuthor_Titleen1Null(); else HeadAuthorsRow.HdAuthor_Titleen1 = HdAuthor_Titleen1;
            if (string.IsNullOrEmpty(HdAuthor_Titleen2)) HeadAuthorsRow.SetHdAuthor_Titleen2Null(); else HeadAuthorsRow.HdAuthor_Titleen2 = HdAuthor_Titleen2;
            if (string.IsNullOrEmpty(HdAuthor_Phone)) HeadAuthorsRow.SetHdAuthor_PhoneNull(); else HeadAuthorsRow.HdAuthor_Phone = HdAuthor_Phone;
            if (string.IsNullOrEmpty(HdAuthor_Fax)) HeadAuthorsRow.SetHdAuthor_FaxNull(); else HeadAuthorsRow.HdAuthor_Fax = HdAuthor_Fax;
            if (string.IsNullOrEmpty(HdAuthor_Email)) HeadAuthorsRow.SetHdAuthor_EmailNull(); else HeadAuthorsRow.HdAuthor_Email = HdAuthor_Email;

            HeadAuthorsRow.HdAuthor_PreTitlear = HdAuthor_PreTitlear;
            HeadAuthorsRow.HdAuthor_Namear = HdAuthor_Namear;
            HeadAuthorsRow.HdAuthor_Titlear1 = HdAuthor_Titlear1;

            int rowsAffected = HeadAuthorsAdapter.Update(HeadAuthorsTable);

            return rowsAffected == 1;
        }

        #endregion

        #region DeleteAuthorities
        [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
        public bool DeleteAuthorty(int HdAuthor_ID)
        {
            int rowsAffected = HeadAuthorsAdapter.Delete(HdAuthor_ID);
            return rowsAffected == 1;
        }
        #endregion

    }
}